\defmodule {ErlangGen}

This class implements random variate generators for the {\em Erlang\/} 
distribution with parameters $k > 0$ and $\lambda > 0$.
This Erlang random variable is the sum of $k$ exponentials with 
parameter $\lambda$ and has mean $k/\lambda$.

The (non-static) \texttt{nextDouble} method simply calls \texttt{inverseF} on the
distribution. 

% (Describe other options: using GammaGen, AcceptanceRejection, 
% RejectionLoglogistic. Also GammaConvolutionGen)

\bigskip\hrule

\begin{code}
\begin{hide}
/*
 * Class:        ErlangGen
 * Description:  random variate generators for the Erlang distribution
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author       
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.randvar;\begin{hide}
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;
\end{hide}

public class ErlangGen extends GammaGen \begin{hide} {
   protected int    k = -1;

\end{hide}\end{code}

\subsubsection* {Constructors}
\begin{code}

   public ErlangGen (RandomStream s, int k, double lambda) \begin{hide} {
      super (s, new ErlangDist(k, lambda));
      setParams (k, lambda);
   }\end{hide}
\end{code} 
\begin{tabb} Creates an Erlang random variate generator with parameters
 \texttt{k} and $\lambda $ = \texttt{lambda},
  using stream \texttt{s}. 
\end{tabb}
\begin{code}

   public ErlangGen (RandomStream s, int k) \begin{hide} {
      this (s, k, 1.0);
   }\end{hide}
\end{code} 
\begin{tabb} Creates an Erlang random variate generator with parameters
 \texttt{k} and $\lambda = 1$, using stream \texttt{s}. 
\end{tabb}
\begin{code}
    
   public ErlangGen (RandomStream s, ErlangDist dist) \begin{hide} {
      super (s, dist);
      if (dist != null)
         setParams (dist.getK(), dist.getLambda());
   }\end{hide}
\end{code}
 \begin{tabb}  Creates a new generator for the distribution \texttt{dist}
    and stream \texttt{s}.
 \end{tabb}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
\subsubsection* {Methods}
\begin{code}

   public static double nextDouble (RandomStream s, int k, double lambda) \begin{hide} {
      return ErlangDist.inverseF (k, lambda, 15, s.nextDouble());
   }\end{hide}
\end{code}
 \begin{tabb}
   Generates a new variate from the Erlang distribution with
   parameters $k = $~\texttt{k} and $\lambda = $~\texttt{lambda},
   using stream \texttt{s}.
 \end{tabb}
\begin{code}

   public int getK()\begin{hide} {
      return k;
   }\end{hide}
\end{code}
\begin{tabb} Returns the parameter $k$ of this object.
\end{tabb}
\begin{hide}\begin{code}

   protected void setParams (int k, double lambda) {
      if (lambda <= 0.0)
         throw new IllegalArgumentException ("lambda <= 0");
      if (k <= 0)
         throw new IllegalArgumentException ("k <= 0");
      this.lambda = lambda;
      this.k = k;
   }
\end{code}
\begin{tabb} Sets the parameter $k$ and $\lambda$ of this object.
\end{tabb}
\begin{code}
}\end{code}
\end{hide}
